package cn.tedu.store.config.util;


import cn.hutool.http.HttpRequest;
import cn.hutool.http.HttpResponse;
import cn.hutool.json.JSONObject;
import cn.hutool.json.JSONUtil;
import cn.tedu.store.entity.dto.HospitalSmsDto;

import java.util.HashMap;
import java.util.Map;


/**
 * @BelongsProject: hesuan_test_zhijianghospital
 * @BelongsPackage: com.zhijiang.common.util
 * @Author: JunFu
 * @CreateTime: 2022-09-07  19:11
 * @Description: TODO
 * @Version: 1.0
 */
public class MassageUtil {
   public  static void smsUtil(HospitalSmsDto hospitalSmsDto){
       String urlStr = "http://192.168.1.110:8081/SmsServer.ashx";
       //创建json对象作为requestBody
       JSONObject jsonObject = new JSONObject();
       jsonObject.put("phone",hospitalSmsDto.getPhone());
       jsonObject.put("content",hospitalSmsDto.getContent());
       System.out.println(JSONUtil.toJsonStr(jsonObject));
    // 添加请求头信息
       Map<String, String > heads = new HashMap<>();
    // 使用json发送请求，下面的是必须的
       heads.put("Content-Type", "application/json;charset=UTF-8");
    /**
     ** headerMap是添加的请求头，
     body是传入的参数，这里选择json，后端使用@RequestBody接收
     */
       HttpResponse response = HttpRequest.post(urlStr)
               .headerMap(heads, false)
               .body(String.valueOf("<request><id>1</id><phone>"+hospitalSmsDto.getPhone()+"</phone><content>"+hospitalSmsDto.getContent()+"</content></request>"))
               .timeout(5 * 60 * 1000)
               .execute();
   }
}
